package test1;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 局部内部类
 */
public class LoualInnerClassDemo {
    public static void main(String[] args) {
        final int a = 2;
        //局部内部类
        class Foo {
            int b = 1;
            public int add() {
                return a+b;
            }
        }
        Foo f = new Foo();
        System.out.println(f.add());
        //按照字符串最后一个字母排序
        String[] names = {"Andy","Tom","John","Mac"};
        class ByLastChar implements Comparator<String> {
            public int compare (String s1,String s2) {
                return s1.charAt(s1.length()-1)-s2.charAt(s2.length()-1);
            }
        }
        Arrays.sort(names,new ByLastChar());
        System.out.println(Arrays.toString(names));
    }
}
